package com.example.mytest327;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.ContentInfo;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.clj.fastble.data.BleDevice;

import java.util.List;

public class BluetoothListAdapter extends RecyclerView.Adapter<BluetoothListAdapter.HolderView> {



    private List<BleDevice> mDeviceList;
    private Context mContext;


    public BluetoothListAdapter(List<BleDevice> deviceList,Context context){
        this.mContext = context;
        this.mDeviceList = deviceList;
    }

    @NonNull
    @Override
    public HolderView onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(mContext).inflate(android.R.layout.simple_list_item_1,null);
        return new HolderView(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull HolderView holder, int position) {
        holder.mTvMac.setText(mDeviceList.get(position).getMac());
    }

    @Override
    public int getItemCount() {
        return mDeviceList.size();
    }

    public void addDevice(BleDevice device){
        mDeviceList.add(device);
        notifyDataSetChanged();
    }

    static class HolderView extends   RecyclerView.ViewHolder{
        TextView mTvMac;
        public HolderView(@NonNull View itemView) {
            super(itemView);
            mTvMac = itemView.findViewById(android.R.id.text1);
        }
    }
}
